/*
 * main.cpp
 *
 *  Created on: Feb 25, 2013
 *      Author: RDU
 */

#include "main.h"
#include "../Camera/mycamera.h"
#include "../GUI/myframe.h"
#include "../ImageStitching/autostitch.h"

IMPLEMENT_APP(MyApp);

bool MyApp::OnInit(){
	wxInitAllImageHandlers();

	//BasicStitching stitcher;
	//stitcher.StitchImages();

	MyFrame *m_pFrame=new MyFrame(NULL, wxID_ANY, wxT("Image Stitching"), wxDefaultPosition, wxSize( 930,630 ), wxDEFAULT_FRAME_STYLE);
	m_pFrame->Show(true);

	MyCamera *cameras=new MyCamera();
	cameras->m_pFrame=m_pFrame;
	m_pFrame->m_camera=cameras;

	//create the thread
	m_pWorkerThread=new WorkerThread(m_pFrame);
	if(m_pWorkerThread->Create() != wxTHREAD_NO_ERROR)
	{
		wxExit();
	}

	m_pWorkerThread->m_camera=cameras;

	//start the thread
	if(m_pWorkerThread->Run() != wxTHREAD_NO_ERROR)
	{
		wxExit();
	}

	return true;
}

int MyApp::OnExit()
{
	if(m_pWorkerThread != NULL)
	{
		m_pWorkerThread->Delete();
	}
	m_pWorkerThread=NULL;

	return wxApp::OnExit();
}

